<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文件上传客户列表</title>
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css">
</head>
<body>
<div class="container">
    <div>
        <button id="reback-btn">返回</button>
    </div>
    <h1>文件上传客户列表</h1>
    <table class="table table-bordered" id='userTable'>
        <thead>
        <tr>
            <th>客户姓名</th>
            <th>性别</th>
            <th>年龄</th>
            <th>身高</th>
            <th>体重</th>
            <th>收入（万/元）</th>
            <th>是否有车</th>
            <th>是否有房</th>
            <th>是否离异</th>
            <th>民族</th>
            <th>学历</th>
            <th>职业</th>
            <th>户籍所在地</th>
            <th>现居住地</th>
            <th>性格</th>
            <th>朋友接受</th>
            <th>对象要求</th>
            <th>用户编号</th>
            <th>操作</th>
        </tr>
        </thead>
    </table>
    <!-- 添加审核通过和审核不通过按钮 -->
    <div>
        <button id="approve-btn">审核通过</button>
        <button id="reject-btn">审核不通过</button>
    </div>


</div>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
    $(function () {
        var uploadRecordId = "[[${uploadRecordId}]]"
        console.log("获取文件的id为"+uploadRecordId);
        var requestBody = {
            "pageNum": 1,
            "pageSize": 100,
            "param": {
                "fileId": uploadRecordId
            }
        };
        console.log("后端传参为："+requestBody);
        // 设置请求的 Content-Type 为 application/json
        $.ajax({
            url: '/tempUser/select',
            type: 'POST',
            contentType: 'application/json',
            data: JSON.stringify(requestBody),
            success: function (data) {
                var tableHtml = '<tbody>';
                var userInfo = data.data
                for (var i = 0; i < userInfo.length; i++) {
                    tableHtml += '<tr><td>' + userInfo[i].name +
                        '</td><td>' + userInfo[i].gender +
                        '</td><td>' + userInfo[i].age +
                        '</td><td>' + userInfo[i].height +
                        '</td><td>' + userInfo[i].weight +
                        '</td><td>' + userInfo[i].income +
                        '</td><td>' + userInfo[i].hasCar +
                        '</td><td>' + userInfo[i].hasHouse +
                        '</td><td>' + userInfo[i].isDivorced +
                        '</td><td>' + userInfo[i].nation +
                        '</td><td>' + userInfo[i].education +
                        '</td><td>' + userInfo[i].occupation +
                        '</td><td>' + userInfo[i].baseAddress +
                        '</td><td>' + userInfo[i].baseAddress +
                        '</td><td>' + userInfo[i].currentAddress +
                        '</td><td>' + userInfo[i].friendEvaluation +
                        '</td><td>' + userInfo[i].idealType +
                        '</td><td>' + userInfo[i].userId +
                        '</td><td><button class="delete-btn" data-id="' + userInfo[i].id +
                        '">删除</button><button class="update-btn" data-id="'
                        + userInfo[i].id + '">修改</button>' +
                        '<button class="upload-btn" data-id="' + userInfo[i].id + '">上传图片</button>' +
                        '<button class="upload-head-btn" data-id="' + userInfo[i].id + '">上传头像图片</button>' +
                        '</td></tr>';
                }
                tableHtml += '</tbody>';
                // 将 HTML 表格插入到页面中
                $("#userTable").append(tableHtml)

                // 添加删除、查看和通过按钮的点击事件处理程序
                $('.delete-btn').click(function () {
                    var userId = $(this).data('id');
                    // 发送删除请求
                    console.log('id:',userId);
                    $.get('/user/delete/'+userId, function () {
                        // 删除成功后刷新表格
                        console.log('id:',userId);
                        location.reload();
                    });

                });
                // 修改窗口
                $('.update-btn').click(function () {
                    var id = $(this).data('id');
                    // 根据uuid 跳转客户信息修改页面
                        window.location.href = '/updateUserInfo/' + id;
                })

                // 上传图片窗口
                $('.upload-btn').click(function () {
                    var id = $(this).data('id');
                    // 发送查看请求
                    // 根据uuid 跳转到上传图片页面
                    window.location.href = '/uploadImage/' + id;
                })
                // 上传头像图片窗口
                $('.upload-head-btn').click(function () {
                    var id = $(this).data('id');
                    // 发送查看请求
                    // 根据uuid 跳转到上传图片页面
                    window.location.href = '/uploadHeadImage/' + id;
                })
            }
        });

        // 绑定审核通过按钮的点击事件
        $('#approve-btn').click(function () {
            // 发送审核通过请求
            approveUsers();
        });

        // 绑定审核不通过按钮的点击事件
        $('#reject-btn').click(function () {
            // 发送审核不通过请求
            rejectUsers();
        });
        // 绑定审核通过按钮的点击事件
        $('#reback-btn').click(function () {
            // 发送审核通过请求
            window.location.href = '/index';
        });

    });
    // 发送审核通过请求
    function approveUsers() {
        var uploadRecordId = "[[${uploadRecordId}]]";
        console.log("test ---approveUsers"+uploadRecordId+"//");
        var requestBody = {
            "id": uploadRecordId,
            "isApproved": true
        };
        $.ajax({
            url: "/file/approvedUploadInfo",
            type: "post",
            contentType: 'application/json',
            data: JSON.stringify(requestBody),
            success: function (data) {
                //返回网页
                window.location.href = '/index';
            }
        })
    }

    // 发送审核不通过请求
    function rejectUsers() {
        var uploadRecordId = "[[${uploadRecordId}]]"
        console.log("test ---approveUsers"+uploadRecordId+"//");
        var requestBody = {
            "id": uploadRecordId,
            "isApproved": false
        };
        $.ajax({
            url: "/file/approvedUploadInfo",
            type: "post",
            contentType: 'application/json',
            data: JSON.stringify(requestBody),
            success: function (data) {
                window.location.href = '/index';
            }
        })
    }


</script>
</body>
</html>